/*
 * httphandle200.cpp
 *
 *  Created on: Apr 27, 2009
 *      Author: kuncai
 */
#ifndef HTTPHANDLE200_H_
#define HTTPHANDLE200_H_
#include <fstream>
using namespace std;
#include "log.h"
#include "httphandle.h"
class HttpHandle200: public HttpHandle{
	void ProcessRequest(HttpRequest* httpRequest, HttpResponse* httpResponse){
		//read url file
		string sFilename = "."+httpRequest->GetParam("url"); 
		string htmlstr="";
		string tempstr="";
		//ifstream fin(sFilename.c_str(), std::ios::in|std::ios::binary);
		ifstream fin(sFilename.c_str(), std::ios::in|std::ios::binary);
		if(fin){
			//open file success
			/*
			while(getline(fin,tempstr)){
				htmlstr += tempstr+"\n";
			}
			*/
			fin.close();
			Log::Debug("file path:%s\n",sFilename.c_str());
			FILE* fd = fopen(sFilename.c_str(),"rb") ;
			 char img[65536];
			Log::Debug("img sizeof is %d\n",sizeof(img));
			//fin.read(img,sizeof(img));
			fread(img,sizeof(img),1,fd);
			httpResponse->SetStatus("200");
			httpResponse->SetReason("OK");
			string simg(img,strlen(img));
			httpResponse->SetContent(simg);
			if(successor != NULL){
				successor->ProcessRequest(httpRequest, httpResponse);
			}
		}else{
			//open file fail
			if(error != NULL){
				error->ProcessRequest(httpRequest, httpResponse);
			}
		}
		//end read url file

	}
};
#endif /* HTTPHANDLE200_H_ */
